<%
  title = if !scope[:stage_in_status_bar].canRun() && scope[:stage_in_status_bar].getErrorMessage()
            scope[:stage_in_status_bar].getErrorMessage()
          elsif com.thoughtworks.go.util.GoConstants::DEFAULT_APPROVED_BY == scope[:stage_in_status_bar].getApprovedBy()
            "Automatically approved"
          elsif scope[:stage_in_status_bar].getApprovedBy().blank?
            "Awaiting approval"
          else
            "Approved by #{scope[:stage_in_status_bar].getApprovedBy()}"
          end

  clazz = scope[:stage_in_status_bar].isAutoApproved() ?
            "auto" :
            "manual"

stage_name = scope[:stage_in_status_bar].getName()
trigger_id = "stage_bar_trigger_" + stage_name
scope[:html_opts] = {:class => clazz, :title=> title, :id => trigger_id }

if scope[:stage_in_status_bar].canRun() && !scope[:stage_in_status_bar].isScheduled() %>
    <%== link_blocking_post_to_server :name=>" ",
                                      :html => scope[:html_opts],
                                      :url => run_stage_path(:stage_name => stage_name) %>
<% else %>
    <span class="<%= clazz %>" title="<%= title %>" id="<%= trigger_id %>"> </span>
<% end %>

